package com.briup.bookstore.web.controller;

import com.briup.bookstore.dto.OrderDeliveryDTO;
import com.briup.bookstore.dto.OrderSearchDTO;
import com.briup.bookstore.response.Result;
import com.briup.bookstore.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: OrderController
 * @Description: 订单模块相关接口
 * @Author: songjl
 * @Date: 2023/7/24 16:06
 * @Version: v1.0
 */
@RestController
@Api(tags = "订单模块")
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("分页多条件查询订单信息")
    @GetMapping("{pageNum}/{pageSize}")
    private Result getPageOrder(@PathVariable Integer pageNum,
                                @PathVariable Integer pageSize,
                                OrderSearchDTO orderSearchDTO) {
        return Result.success(orderService.getPageOrder(pageNum, pageSize, orderSearchDTO));
    }

    @ApiOperation("根据订单编号查询订单信息")
    @GetMapping("{orderId}")
    private Result getById(@PathVariable String orderId) {
        return Result.success(orderService.getOrderById(orderId));
    }

    @ApiOperation("关闭订单")
    @PutMapping("close/{orderId}")
    private Result closeOrder(@PathVariable String orderId) {
        orderService.closeOrder(orderId);
        return Result.success();
    }

    @ApiOperation("填写发货信息")
    @PutMapping("delivery")
    private Result delivery(@RequestBody OrderDeliveryDTO orderDeliveryDTO) {
        orderService.delivery(orderDeliveryDTO);
        return Result.success();
    }
}
